"""
Copyright (c) 2022 Huawei Technologies Co.,Ltd.

openGauss is licensed under Mulan PSL v2.
You can use this software according to the terms and conditions of the Mulan PSL v2.
You may obtain a copy of Mulan PSL v2 at:

          http://license.coscl.org.cn/MulanPSL2

THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
See the Mulan PSL v2 for more details.
"""
"""
Case Type   : cm_install
Case Name   : cm_install显示帮助信息
Create At   : 2022/11/15
Owner       : opentestcase012
Description :
    1.cm_install显示帮助信息
Expect      :
    1.执行成功，显示帮助信息正确且与实际一致
History     :
"""
import os
import unittest

from testcase.utils.Common import Common
from testcase.utils.Logger import Logger
from yat.test import Node
from yat.test import macro


class Tools(unittest.TestCase):
    def setUp(self):
        self.log = Logger()
        self.log.info(f'-----{os.path.basename(__file__)} start-----')
        self.pri_user = Node('PrimaryDbUser')
        self.common = Common()
        self.cm_tool = os.path.join(macro.DB_INSTANCE_PATH, '..', 'app',
                                    'tool', 'cm_tool')

    def test_standby(self):
        text = '-----step1:cm_install显示帮助信息 expect:成功-----'
        self.log.info(text)
        cmd = f'cd {self.cm_tool};' \
            f'./cm_install -?'
        self.log.info(cmd)
        help_res = self.common.get_sh_result(self.pri_user, cmd)
        help_msg = ['cm_install is a utility to deploy CM tool '
                    'to openGauss database cluster',
                    'cm_install -? | --help',
                    'cm_install -X XMLFILE [-e envFile] --cmpkg=cmpkgPath',
                    '-X                                 '
                    'Path of the XML configuration file',
                    '-e                                 Path of env file.',
                    'Default value "~/.bashrc".',
                    '--cmpkg                            Path of CM pacakage.',
                    '-?, --help                         '
                    'Show help information for this',
                    'utility, and exit the command line mode.']
        for content in (help_msg):
            self.log.info(content)
            self.assertTrue(help_res.find(content) > -1)

    def tearDown(self):
        self.log.info('-----无需清理环境-----')
        self.log.info(f'-----{os.path.basename(__file__)} end-----')
